﻿(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/speedTab/speedTab.html", {
        // This function is called whenever a user navigates to this page. It
        // populates the page elements with the app's data.
        ready: function (element, options) {
            console.log("ready spped");
            attachCommontHandlres();
            document.getElementById("inpt_speed").addEventListener("change", updateSpeed, false);
            document.getElementById("inpt_oposit").addEventListener("change", oppositChanged, false);
            document.getElementById("inpt_time").addEventListener("change", nikeChanged, false);
            document.getElementById("slct_dist").addEventListener("change", updateGoalSection, false);
            document.getElementById("slct_time").addEventListener("change", updateGoalSection, false);
            document.getElementById("inpt_g_dist").addEventListener("change", updateGoalSection, false);
        },
        unload: function () {
            // TODO: Respond to navigations away from this page.
        },

        updateLayout: function (element, viewState, lastViewState) {
        /// <param name="element" domElement="true" />

        // TODO: Respond to changes in viewState.
        }
    });
    function oppositChanged(e) {
        var os = e.srcElement.value;
        var s = getFromOppositSpeed(os);
        setFloatValue("inpt_time", getNikeStyleSpeed(s));
        setFloatValue("inpt_speed", s);
        updateGoalSection();
    }
    function nikeChanged(e) {
        var os = e.srcElement.value;
        var s = getNikeStyleSpeed(os);
        setFloatValue("inpt_oposit", getOppositSpeed(s));
        setFloatValue("inpt_speed", s);
        updateGoalSection();
    }
    
})();
function updateSpeed() {
    var s = getFloatValue("inpt_speed");
    setFloatValue("inpt_time", getNikeStyleSpeed(s));
    setFloatValue("inpt_oposit", getOppositSpeed(s));
    updateGoalSection();
}
function updateGoalSection() {
    console.log("updateGoalSection");
    var s = getFloatValue("inpt_speed");
    var d = getFloatValue("inpt_g_dist");
    if (isNaN(d) ||d == 0) {
        d = 10;
        setFloatValue("inpt_g_dist", 10);
    }
    d = getDistance(d);
    t = d / s;
    t = getTime(t);
    setFloatValue("inpt_g_time", t);
}
